package smetana.modules.business;

import smetana.domain.raw.Manager;
import smetana.modules.business.meta.Commit;
import smetana.util.Pivot;
import smetana.mapper.raw.ManagerMapper;

/**
 * @author dmitry.mamonov
 */
class BusinessManagerImpl extends BaseImpl implements BusinessManager {
    @Override
    @Commit
    public Manager newManager(String text) {
        ManagerMapper mapper = sql.getMapper(ManagerMapper.class);
        Manager manager = new Manager(mapper.nextId());
        manager.setManagerName(text);
        mapper.insert(manager);
        return mapper.findById(manager.getId());
    }

    @Override
    public Manager findManagerById(Integer id) {
        if (id == null) {
            return null;
        } else {
            ManagerMapper mapper = sql.getMapper(ManagerMapper.class);
            Manager manager = mapper.findById(id);
            return manager;
        }
    }

    @Override
    @Commit
    public void saveManager(Manager manager) {
        ManagerMapper mapper = sql.getMapper(ManagerMapper.class);
        mapper.update(manager);
    }

    @Override
    public java.util.List<Manager> listManagers() {
        ManagerMapper mapper = sql.getMapper(ManagerMapper.class);
        return mapper.listAll();
    }


}
